﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace sWarranty.WEB
{
    public partial class FindProvince : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string updateParentScript =
                 @"function updateParentWindow2(a)
                 {                                                                               
                   var fName2= a; //document.getElementById('dropShop2').value;     
                   var arrayValues2= new Array(fName2);
                   window.opener.updateValues2(arrayValues2);       
                   window.close(); 
                 }";
            this.ClientScript.RegisterStartupScript(this.GetType(), "UpdateParentWindow2", updateParentScript, true);

            //btnFind.Attributes.Add("onclick", "updateParentWindow2('101|5030')");
            btnFind.Focus();

        }
        protected void btnFind_Click(object sender, EventArgs e)
        {
            litData.Text = "";
            Entities db = new Entities();
            var lo = from p in db.TB_CM_PROVINCE
                     from d in db.TB_CM_DISTRICT
                     where d.PROVINCE_ID == p.ID
                     select new
                     {
                         PID = p.ID,
                         DID = d.ID,
                         PName = p.NAME,
                         DName = d.NAME
                     };
            if (!string.IsNullOrEmpty(txtProvince.Text))
                lo = lo.Where(k => k.PName.ToLower().Contains(txtProvince.Text.ToLower()));
            if (!string.IsNullOrEmpty(txtDistrict.Text))
                lo = lo.Where(k => k.DName.ToLower().Contains(txtDistrict.Text.ToLower()));

            if (lo.Count() > 0)
            {
                divData.Visible = true;
                foreach (var item in lo)
                {
                    string returnValue = item.PID + "&" + item.PName + "|" + item.DID + "&" + item.DName;
                    litData.Text += "<tr>";
                    litData.Text += "   <td>" + item.PName;
                    litData.Text += "   </td>";
                    litData.Text += "   <td>" + item.DName;
                    litData.Text += "   </td>";
                    litData.Text += "   <td><input type='button' value='Select' id='btnSelect' onclick=\"updateParentWindow2('" + returnValue + "')\" class='button' />";
                    litData.Text += "   </td>";
                    litData.Text += "</tr>";
                }
            }
            else
            {
                divData.Visible = false;

                ShowInfo("No Locationfound");
            }
        }


        public void ShowError(string er)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification error\"><div class=\"text\"><p><strong>" + er + " </strong> </p></div></div>", false);
        }
        public void ShowError(Exception ex)
        {
            if (ex.InnerException != null)
            {
                string er = ex.InnerException.Message + " at " + ex.TargetSite.Name + "()";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification error\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
            }
        }
        public void ShowInfo(string er)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification info\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
        }
        public void ShowInfo(Exception ex)
        {
            if (ex.InnerException != null)
            {
                string er = ex.InnerException.Message + " at " + ex.TargetSite.Name + "()";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification info\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
            }
        }
        public void ShowWarning(string er)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification warning\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
        }
        public void ShowWarning(Exception ex)
        {
            if (ex.InnerException != null)
            {
                string er = ex.InnerException.Message + " at " + ex.TargetSite.Name + "()";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification warning\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
            }
        }
        public void ShowSuccess(string er)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification success\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
        }
        public void ShowSuccess(Exception ex)
        {
            if (ex.InnerException != null)
            {
                string er = ex.InnerException.Message + " at " + ex.TargetSite.Name + "()";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification success\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
            }
        }
        public void ShowTip(string er)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification tip\"><div class=\"text\"><p><strong> " + er + "</strong> </p></div></div>", false);
        }
        public void ShowTip(Exception ex)
        {
            if (ex.InnerException != null)
            {
                string er = ex.InnerException.Message + " at " + ex.TargetSite.Name + "()";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "abcdefgh", "<div class=\"notification tip\"><div class=\"text\"><p><strong> " + er + " </strong></p></div></div>", false);
            }
        }
    }
}